// demo/main.go
package main

import (
	"fmt"
	"swig_go_cpp/wrapper"
	"time"
)

type MyObserver struct {
	name string
}

func (o *MyObserver) OnMessage(msg wrapper.Message) {
	fmt.Printf("[%s] 收到消息: %s\n", o.name, msg.Content)
}

func (o *MyObserver) OnError(errorCode int) {
	fmt.Printf("[%s] 错误码: %d\n", o.name, errorCode)
}

func main() {
	sdk := wrapper.NewSDK()

	observer := &MyObserver{name: "Observer1"}
	listenID, err := sdk.Listen("topic1", observer)
	if err != nil {
		fmt.Printf("错误: %v\n", err)
		return
	}

	time.Sleep(2 * time.Second)
	sdk.Stop(listenID)
}
